« Repairing a KITSRUS Kit 150 for ICSP | Main | EEPROM read/write code for CC5X »
Getting up to speed with the PIC16F737 (January 29, 2008)
Porting code between PIC micros from the same product range is normally a smooth process: redefine a few pins, change some clock-speed constants, and add support code for that new integrated peripheral widget.
Sometimes though, there's a large hurdle before you can even begin. The 16F737 posed such a hurdle, there are a few clever lines of code required to put the device into all digital I/O running under the internal oscillator (intosc).
First, you must set the internal oscillator to a sane speed, something in the MHz range. This is controlled through the OSCCON
register. I wanted 4MHz, so bits 4-6 must be 110
. You may be able to leave SCS
set to 00
, but I set them to internal RC (10
) just in case. OSCCON = 0b01100010;
You're next task, is disabling the default analog functions of some I/O pins. The relevant registers are CMCON
and ADCON1
The CMCON register is already configured correctly on the 737, but old habits make us configure it anyway. We want all comparators off, which is 00000111
or CMCON = 0x07;
.
The ADCON1 register uses the last 4 bits to control input selection. The last option gives us all off (1111
). So, ADCON1 = 0x0F;
.
Putting all this together, gives us the following short header to our main code:
OSCCON = 0b01100010;
CMCON = 0x07;
ADCON1 = 0x0F;
Code (7) PIC (8)
Posted by spiffed at January 29, 2008 10:44 PM